<?php
function db_struct_create( $rLink )
{
	//This function create db structure if not present
	//$rLink is the db connection resource

    //Create categories table
	$sQuery = 'CREATE TABLE IF NOT EXISTS categories (
	  category_id int(11) NOT NULL auto_increment,
	  category_text varchar(255) NOT NULL,
	  PRIMARY KEY  (category_id),
      UNIQUE KEY category_name (category_text)
	) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;';
	mysql_query( $sQuery, $rLink )
        or die("Failed to create structure:\n" . mysql_error( ) );

	//Create languages table
    $sQuery='CREATE TABLE IF NOT EXISTS languages (
	  language_id int(11) NOT NULL auto_increment,
	  language_text varchar(255) NOT NULL,
	  PRIMARY KEY  (language_id),
	  UNIQUE KEY language_text (language_text)
	) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;';
	mysql_query( $sQuery, $rLink )
        or die("Failed to create structure:\n" . mysql_error( ) );
	
	//Create messages table
	$sQuery='CREATE TABLE IF NOT EXISTS messages (
	  message_id int(11) NOT NULL auto_increment,
	  language_id int(11) NOT NULL,
	  product_id int(11) NOT NULL,
	  message_type int(11) NOT NULL,
	  message_text text NOT NULL,
	  PRIMARY KEY  (message_id),
	  KEY language_id (language_id),
	  KEY product_id (product_id)
	) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=35 ;';
	mysql_query( $sQuery, $rLink )
        or die("Failed to create structure:\n" . mysql_error( ) );

	//Create products table
	$sQuery='CREATE TABLE IF NOT EXISTS products (
      product_id int(11) NOT NULL auto_increment,
	  product_code varchar(32) NOT NULL,
	  category_id int(11) NOT NULL,
	  product_price decimal(10,2) NOT NULL,
	  PRIMARY KEY  (product_id),
	  UNIQUE KEY product_code (product_code),
	  KEY product_category (category_id)
	) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;';
	mysql_query( $sQuery, $rLink )
        or die("Failed to create structure:\n" . mysql_error( ) );
}
?>